<?php 
class Model_DAO_Section
{
    public function lists($start,$length)
    {
        global $dbconfig;
        $listsection = array();
        try
        {
            $sql = "select * from ".table_prefix("section")." order by id ASC limit {$start},{$length}";;
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_row() != 0)
            {
                $arrs = $dbconfig->fetch_array();
                foreach($arrs as $arr)
                {
                    $section = CreateObject("Model_DAO_Section");
                    $section->id = $arr["id"];
                    $section->title = $arr["title"];
                    $section->order = $arr["order"];
                    $section->create_by = $arr["create_by"];
                    $section->updated  = $arr["updated"]; 
                    $section->status = $arr["status"];       
                    
                    $listsection[] = $section;
                }   
            }
            else
            {
                $listsection = NULL;
            }
            $dbconfig->close();
            return $listsection;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $listsection;
        }
    }
    
    public function get($id)
    {
        global $dbconfig;
        $section = NULL;
        try
        {
            $sql = "select * from ".table_prefix("section")." where id='".$dbconfig->sqlQuote($id)."'";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_row() != 0)
            {
                $arr = $dbconfig->fetch_array();
                $arr = $arr[0];
                $section = CreateObject("Model_Entity_Section");
                $section->id = $arr["id"];
                $section->title = $arr["title"];
                $section->order = $arr["order"];
                $section->create_by = $arr["create_by"];
                $section->updated = $arr["updated"]; 
                $section->status = $arr["status"];      
                
            }
            else
            {
                $section = NULL;
            }
            $dbconfig->close();
            return $section;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $section;
        }
    }
    
    public function create($section)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "insert into ".table_prefix("section")."(title,order,create_by,updated,status) values ('".$dbconfig->sqlQuote($acount->title)."','".$dbconfig->sqlQuote($section->order)."','".$dbconfig->sqlQuote($section->create_by)."','".$dbconfig->sqlQuote($section->updated)."','".$dbconfig->sqlQuote($section->status)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
    
    public function delete($id)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "delete from ".table_prefix("section")." where id = '".$dbconfig->sqlQuote($section->id)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
    
    public function update($section)
    {
        global $dbconfig;
        $status = false;
        try
        {
            $sql = "update ".table_prefix("section")." set title='".$dbconfig->sqlQuote($acount->title)."', order = '".$dbconfig->sqlQuote($section->order)."', create_by = '".$dbconfig->sqlQuote($section->create_by)."', updated = '".$dbconfig->sqlQuote($section->updated)."' where id ='".$dbconfig->sqlQuote($section->id)."';";
            $dbconfig->open();
            $dbconfig->query($sql);
            if($dbconfig->num_affected() != 0)
            {
                $status = true;
            }
            $dbconfig->close();
            return $status;   
        }
        catch(MyException $ex)
        {
            $ex->__toString();
            return $status;
        }
    }
}
?>